<?php
include "../sql/conn.php";
if (isset($_POST['q']))
{
    $q = $_POST['q'];
} 
else
{
    $q = '';
}    
$q = str_replace("'", "''", $q);

if($_REQUEST['field']=="customer"){
    $from="customer";
    $id="idCustomer";
    $nama="namaCustomer";
}
elseif($_REQUEST['field']=="kategoribarang"){
    $from="kategori_barang";
    $id="idKategoriBarang";
    $nama="namaKategoriBarang";
}
elseif($_REQUEST['field']=="barang"){
    $from="barang";
    $id="idBarang";
    $nama="namaBarang";
}

$query = mysql_query("
        SELECT 
            *
        FROM 
            $from 
        WHERE 
            ( `$id` LIKE '%$q%' or `$nama` LIKE '%$q%') 
        ") or die(mysql_error());		

$data = array(); 
while($row = mysql_fetch_object($query)){
    $data[] = $row; 
}
die(json_encode($data)); 
?>